package com.detective.sherlock;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

	static final private int CHOOSE_THIEF = 0;
	
	TextView tvInfo;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		Button answerButton = (Button) findViewById(R.id.buttonAnswer);
		tvInfo = (TextView) findViewById(R.id.textViewAnswer);

		answerButton.setOnClickListener(this);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent(MainActivity.this, ThiefActivity.class);
		startActivityForResult(intent, CHOOSE_THIEF);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (requestCode == CHOOSE_THIEF) {
			if (resultCode == RESULT_OK) {
				String thiefname = data.getStringExtra(ThiefActivity.THIEF);
				tvInfo.setText(thiefname);
			} else {
				tvInfo.setText(""); 
			}
		}

	}

}
